<?php

class my_order_list{
public function index()
{
$email = strim($GLOBALS['request']['email']);
$pwd = strim($GLOBALS['request']['pwd']);
$status_type = intval($GLOBALS['request']['status_type']);
$tel = $GLOBALS['request']['tel'];
$user = user_check($email,$pwd);
$user_id  = intval($user['id']);
$root = array();
$condition=$this->deal_order_type($status_type);
$page = intval($GLOBALS['request']['page']);
$page=$page==0?1:$page;
$page_size = PAGE_SIZE;
$limit = (($page-1)*$page_size).','.$page_size;
if(empty($tel))
{
if($user_id>0)
{
$root['user_login_status'] = 1;
$sql_count = 'SELECT COUNT(id)  FROM '.DB_PREFIX.'supplier_location_order  WHERE user_id = '.$user_id.'   ';
$count=$GLOBALS['db']->getOne($sql_count);
$page_total = ceil($count/$page_size);
$list = $GLOBALS['db']->getAll('select slo.id,sl.name as supplier_name,slo.order_time,slo.order_tel,slo.status from '.DB_PREFIX.'supplier_location_order as slo left join '.DB_PREFIX."supplier_location as sl on slo.sid=sl.id  where {$condition}  slo.user_id = ".$user_id.'  order by slo.create_time desc limit '.$limit);
}
else
{
$root['user_login_status'] = 0;
$root['info'] = '请先登入';
$root['return'] = 0;
output($root);
}
}else{
if(!check_mobile($tel)){
$root['info']='您好，您的手机号格式不正确!';
$root['return']=0;
output($root);
}
$sql_count = 'SELECT COUNT(id)  FROM '.DB_PREFIX."supplier_location_order  WHERE order_tel ={$tel}   ";
$count=$GLOBALS['db']->getOne($sql_count);
$page_total = ceil($count/$page_size);
$list = $GLOBALS['db']->getAll('select slo.id,sl.name as supplier_name,slo.order_time,slo.order_tel,slo.status from '.DB_PREFIX.'supplier_location_order as slo left join '.DB_PREFIX."supplier_location as sl on slo.sid=sl.id  where {$condition}  slo.order_tel = {$tel}  order by slo.create_time desc limit ".$limit);
}
foreach($list as $lk=>$lv)
{
$list[$lk]['order_time']=Date('Y-m-d H:m:s',$lv['order_time']);
}
$root['item']=$list;
$root['page'] = array('page'=>$page,'page_total'=>$page_total);
output($root);
}
function deal_order_type($type)
{
switch($type)
{
case 0:
$condent='   ';
$condent=' slo.status=0 and  ';
break;
case 1:
$condent=' slo.status=1 and  ';
break;
case 2:
$condent=' slo.status=2 and ';
break;
case 3:
$condent=' slo.status=3 and ';
break;
case 4:
$condent=' slo.status=4 and ';
break;
case 5:
$condent='  ';
break;
default:
$condent='  ';
}
return $condent;
}
}
?>